# 生成器
# 概念：是一种创建迭代器的特殊函数
# 优点：节省内存，一次只返回一个结果
# 缺点：只能够迭代一次，不能通过索引访问随机元素，必须按照顺序逐个迭代获取

datas1 = [i for i in range(100)]
print(datas1,datas1.__sizeof__())


datas2 = (i for i in range(100))
print(datas2.__sizeof__())
for data in datas2:
    print(data)
print("="*20)
for data in datas2:
    print(data)

def test():
    yield 10
    yield 20
    return 30
a = test()

try:
    print(type(test()))
    print(next(a))
    print(next(a))
    print(next(a))
except StopIteration as e:
        print(e)


